package org.chinacareer.position.controller.web;

import java.lang.reflect.Field;
import java.util.List;

import org.chinacareer.BaseController;
import org.chinacareer.position.client.MessageClient;
import org.chinacareer.position.config.MyPollingServerListUpdater;
import org.chinacareer.util.SpringContextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.alibaba.nacos.client.naming.NacosNamingService;
import com.alibaba.nacos.client.naming.core.HostReactor;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server;

@RestController
@RequestMapping("/testServerList")
public class TestController extends BaseController {

	@Autowired
	private SpringClientFactory factory;
	
	@RequestMapping("/testBalancer")
	public int testBalancer() throws Exception {
		
	    ILoadBalancer lb =  factory.getLoadBalancer("cts-message"); //指定服务名
		List<Server> allServers = lb.getAllServers();
		System.out.println("allServers>>>>>>>>>>:"+JSON.toJSONString(allServers));
		List<Server> upServers = lb.getReachableServers();
		System.out.println("upServers>>>>>>>>>>>:"+JSON.toJSONString(upServers));
		
		return upServers.size();
	}
    
}
